Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
node-worker-pool
Advanced tools
node-worker-pool is a library for managing a pool of child workers in node.
node-worker-pool is a library for managing a pool of child workers in node.
It's primarily useful for scenarios where you have lots of highly parallelizable tasks you want to perform. It works exclusively via message-passing, so there is no need to share memory.
Specifically, node-worker-pool allows you to define your own worker executable that is capable of communicating over stdin/stdout (via a fairly simple protocol for which I have yet to propertly document :p).
You technically don't have to write this file in node, but for the time being there are only node helper libraries for abstracting away the communciation protocols. Here is an example worker:
worker.js
var workerUtils = require('node-worker-pool/nodeWorkerUtils');
/**
* Executed once when the worker pool first starts
* (before any messages are received)
*/
var initData;
function onInitialize(data) {
initData = data;
}
/**
* Executed each time a message is received from the worker pool.
* Returns the response to the message (response must always be an object)
*/
function onMessage(data) {
return {
initData: initData,
receivedData: data
};
}
if (require.main === module) {
try {
workerUtils.startWorker(onInitialize, onMessage);
} catch (e) {
workerUtils.respondWithError(e);
}
}
workerPool.js
if (require.main === module) {
var workerPool = new WorkerPool(
8, // number of workers
process.execPath, // path to the node binary
'./worker.js', // path to the worker script
{
// The initData object that is passed to each worker exactly once before
// any messages get sent. Workers receive this object via their
// onInitialize callback.
initData: {someUsefulConstant: 42}
}
);
workerPool.sendMessage({message: 'hai!'}).then(function(response) {
console.log(response); // Prints the response object from the worker
});
workerPool.shutDown().then(function() {
console.log('All worker processes have now been killed');
});
}
FAQs
node-worker-pool is a library for managing a pool of child workers in node.
We found that node-worker-pool demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.